From b66b0b74e03d670fbc98823980efae547804fcb7 Mon Sep 17 00:00:00 2001 From: Kalita Alexey Date: Thu, 19 Jan 2017 23:43:56 +0300 Subject: [PATCH] Fixed tests --- tests/build.rs | 14 ++++++--- tests/cargotest/support/mod.rs | 56 ++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/tests/build.rs b/tests/build.rs index c62513ebd..af1ad23e0 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -1906,7 +1906,8 @@ fn example_as_lib() { .file("src/lib.rs", "") .file("examples/ex.rs", ""); - assert_that(p.cargo_process("build"), execs().with_status(0)); + assert_that(p.cargo_process("build").arg("--example=ex"), execs().with_status(0)); + assert_that(&p.example_lib("ex", "lib"), existing_file()); } #[test] @@ -1923,9 +1924,10 @@ fn example_as_rlib() { crate-type = ["rlib"] "#) .file("src/lib.rs", "") - .file("examples/ex.rs", ""); + .file("examples/ex.rs", "fn a() {}"); - assert_that(p.cargo_process("build"), execs().with_status(0)); + assert_that(p.cargo_process("build").arg("--example=ex"), execs().with_status(0)); + assert_that(&p.example_lib("ex", "rlib"), existing_file()); } #[test] @@ -1944,7 +1946,8 @@ fn example_as_dylib() { .file("src/lib.rs", "") .file("examples/ex.rs", ""); - assert_that(p.cargo_process("build"), execs().with_status(0)); + assert_that(p.cargo_process("build").arg("--example=ex"), execs().with_status(0)); + assert_that(&p.example_lib("ex", "dylib"), existing_file()); } #[test] @@ -1963,7 +1966,8 @@ fn example_as_proc_macro() { .file("src/lib.rs", "") .file("examples/ex.rs", ""); - assert_that(p.cargo_process("build"), execs().with_status(0)); + assert_that(p.cargo_process("build").arg("--example=ex"), execs().with_status(0)); + assert_that(&p.example_lib("ex", "proc-macro"), existing_file()); } #[test] diff --git a/tests/cargotest/support/mod.rs b/tests/cargotest/support/mod.rs index 3be209719..de218b6fc 100644 --- a/tests/cargotest/support/mod.rs +++ b/tests/cargotest/support/mod.rs @@ -114,6 +114,25 @@ impl ProjectBuilder { pub fn url(&self) -> Url { path2url(self.root()) } + pub fn target_debug_dir(&self) -> PathBuf { + self.build_dir().join("debug") + } + + pub fn example_lib(&self, name: &str, kind: &str) -> PathBuf { + let prefix = ProjectBuilder::get_lib_prefix(kind); + + let extension = ProjectBuilder::get_lib_extension(kind); + + let lib_file_name = format!("{}{}.{}", + prefix, + name, + extension); + + self.target_debug_dir() + .join("examples") + .join(&lib_file_name) + } + pub fn bin(&self, b: &str) -> PathBuf { self.build_dir().join("debug").join(&format!("{}{}", b, env::consts::EXE_SUFFIX)) @@ -188,6 +207,43 @@ impl ProjectBuilder { buffer } + fn get_lib_prefix(kind: &str) -> &str { + match kind { + "lib" | "rlib" => "lib", + "staticlib" | "dylib" | "proc-macro" => { + if cfg!(windows) { + "" + } else { + "lib" + } + } + _ => unreachable!() + } + } + + fn get_lib_extension(kind: &str) -> &str { + match kind { + "lib" | "rlib" => "rlib", + "staticlib" => { + if cfg!(windows) { + "lib" + } else { + "a" + } + } + "dylib" | "proc-macro" => { + if cfg!(windows) { + "dll" + } else if cfg!(target_os="macos") { + "dylib" + } else { + "so" + } + } + _ => unreachable!() + } + } + fn rm_root(&self) { self.root.rm_rf() } -- 2.30.2